package com.heima.article.feign;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.apis.article.IArticleClient;
import com.heima.article.service.ApAuthorService;

import com.heima.model.atricle.dtos.ArticleDto;
import com.heima.model.atricle.pojos.ApAuthor;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//虽然命名为client，但本质还是一个controller
@RestController
public class ArticleClient implements IArticleClient {

    @Autowired
    private ApAuthorService apAuthorService;

    @Override
    @GetMapping("/api/v1/author/findByUserId/{userId}")
    public ApAuthor findByUserId(@PathVariable("userId") Integer userId){
        return apAuthorService.getOne(Wrappers.<ApAuthor>lambdaQuery().eq(ApAuthor::getUserId, userId));
    }

    @Override
    @PostMapping("/api/v1/author/save")
    public ResponseResult save(@RequestBody ApAuthor apAuthor){
        apAuthorService.save(apAuthor);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    @Override
    public ResponseResult saveArticle(ArticleDto articleDto) {
        return null;
    }

    @Override
    public ApAuthor findByWmUserId(Integer wmUserId) {
        return null;
    }
}
